<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      姓：<input type="text" v-model="fristName" /><br />
      名：<input type="text" v-model="lastName" /><br />
      <p>姓名：{{ fullName }}</p>
      <button @click="changeName">修改姓名</button>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
      const app = new Vue({
        el: "#app",
        data: {
          fristName: "张",
          lastName: "三",
        },
        computed: {
          // 简写
          // fullName() {
          //   return this.fristName + this.lastName;
          // },

          // 完整写法
          fullName: {
            // 获取
            get() {
              return this.fristName + this.lastName;
            },
            // 修改
            set(value) {
              console.log("修改-fullName被重新赋值", value);
              this.fristName = value.slice(0, 1);
              this.lastName = value.slice(1);
            },
          },
        },
        methods: {
          changeName() {
            this.fullName = "刘德华";
          },
        },
      });
    </script>
  </body>
</html>
